package com.ruoyi.web.controller.ydz;

import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.ClinicalDisease;
import com.ruoyi.web.service.IClinicalDiseaseService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 临床招募疾病Controller
 *
 * @author drx
 * @date 2024-04-08
 */
@Controller
@RequestMapping("/ydz/clinicalDisease")
@Api(tags = "临床招募疾病")
public class ClinicalDiseaseController extends BaseController
{
    private String prefix = "ydz/clinicalDisease";

    @Autowired
    private IClinicalDiseaseService clinicalDiseaseService;

    @RequiresPermissions("ydz:clinicalDisease:view")
    @GetMapping()
    public String disease()
    {
        return prefix + "/clinicalDisease";
    }

    /**
     * 查询临床招募疾病列表
     */
    @RequiresPermissions("ydz:clinicalDisease:list")
    @PostMapping("/list")
    @ResponseBody
    @ApiOperation("查询临床招募疾病列表")
    public TableDataInfo list(ClinicalDisease clinicalDisease)
    {
        startPage();
        List<ClinicalDisease> list = clinicalDiseaseService.selectClinicalDiseaseList(clinicalDisease);
        return getDataTable(list);
    }

    /**
     * 导出临床招募疾病列表
     */
    @RequiresPermissions("ydz:clinicalDisease:export")
    @Log(title = "临床招募疾病", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    @ApiOperation("导出临床招募疾病列表")
    public AjaxResult export(ClinicalDisease clinicalDisease)
    {
        List<ClinicalDisease> list = clinicalDiseaseService.selectClinicalDiseaseList(clinicalDisease);
        ExcelUtil<ClinicalDisease> util = new ExcelUtil<ClinicalDisease>(ClinicalDisease.class);
        return util.exportExcel(list, "临床招募疾病数据");
    }

    /**
     * 新增临床招募疾病
     */
    @GetMapping("/add")
    @ApiOperation("新增临床招募疾病")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存临床招募疾病
     */
    @ApiOperation("新增保存临床招募疾病")
    @RequiresPermissions("ydz:clinicalDisease:add")
    @Log(title = "临床招募疾病", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ClinicalDisease clinicalDisease)
    {
        return toAjax(clinicalDiseaseService.insertClinicalDisease(clinicalDisease));
    }

    /**
     * 修改临床招募疾病
     */
    @ApiOperation("修改临床招募疾病")
    @RequiresPermissions("ydz:clinicalDisease:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ClinicalDisease clinicalDisease = clinicalDiseaseService.selectClinicalDiseaseById(id);
        mmap.put("clinicalDisease", clinicalDisease);
        return prefix + "/edit";
    }

    /**
     * 修改保存临床招募疾病
     */
    @ApiOperation("修改保存临床招募疾病")
    @RequiresPermissions("ydz:clinicalDisease:edit")
    @Log(title = "临床招募疾病", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ClinicalDisease clinicalDisease)
    {
        return toAjax(clinicalDiseaseService.updateClinicalDisease(clinicalDisease));
    }

    /**
     * 删除临床招募疾病
     */
    @ApiOperation("删除临床招募疾病")
    @RequiresPermissions("ydz:clinicalDisease:remove")
    @Log(title = "临床招募疾病", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(clinicalDiseaseService.deleteClinicalDiseaseByIds(ids));
    }
}
